package c.j.a.c.q;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Looper;
import android.text.TextUtils;
import c.j.a.c.g$g.b;
import c.j.a.c.g.y;
import c.j.a.d.a.h;
import c.j.a.d.b.e.i;
import c.j.a.d.b.n.a;
import com.ss.android.socialbase.downloader.g.c;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: ToolUtils */
public class d {
    public static Object[] a = new Object[0];
    public static Object[] b = new Object[73];

    public static long a(File file) {
        long j = -1;
        if (file == null) {
            return -1;
        }
        try {
            j = a.J(file.getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return j;
    }

    public static long b(JSONObject jSONObject, String str) {
        try {
            return Long.valueOf(jSONObject.optString(str)).longValue();
        } catch (Exception unused) {
            return 0;
        }
    }

    public static PackageInfo c(c.j.a.b.a.c.a aVar) {
        c k = i.a(y.a()).k(aVar.q);
        if (k == null) {
            return null;
        }
        try {
            return h.e(y.a(), k.e, k.b);
        } catch (Throwable unused) {
            return null;
        }
    }

    public static b d(String str, int i, String str2) {
        b bVar = new b();
        if (TextUtils.isEmpty(str)) {
            return bVar;
        }
        try {
            PackageInfo packageInfo = y.a().getPackageManager().getPackageInfo(str, 0);
            if (packageInfo != null) {
                bVar.b = packageInfo.versionCode;
                bVar.a = 1;
            }
        } catch (Exception unused) {
        }
        return bVar;
    }

    public static <T> T e(T... tArr) {
        for (T t : tArr) {
            if (t != null) {
                return t;
            }
        }
        throw new IllegalArgumentException("args is null");
    }

    public static String f(String... strArr) {
        for (CharSequence charSequence : strArr) {
            if (!TextUtils.isEmpty(charSequence)) {
                return charSequence;
            }
        }
        return "ERROR";
    }

    public static JSONObject g(JSONObject jSONObject, JSONObject jSONObject2) {
        if (jSONObject != null) {
            try {
                Iterator keys = jSONObject.keys();
                while (keys.hasNext()) {
                    String str = (String) keys.next();
                    jSONObject2.put(str, jSONObject.get(str));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return jSONObject2;
    }

    public static JSONObject h(JSONObject... jSONObjectArr) {
        JSONObject jSONObject = new JSONObject();
        if (jSONObjectArr.length != 0) {
            for (JSONObject jSONObject2 : jSONObjectArr) {
                if (jSONObject2 != null) {
                    g(jSONObject2, jSONObject);
                }
            }
        }
        return jSONObject;
    }

    public static void i(Activity activity) {
        if (activity != null && !activity.isFinishing()) {
            activity.finish();
        }
    }

    public static void j(Throwable th) {
        String stringWriter;
        try {
            StringWriter stringWriter2 = new StringWriter();
            th.printStackTrace(new PrintWriter(stringWriter2));
            stringWriter = stringWriter2.toString();
        } catch (Exception unused) {
            stringWriter = null;
        }
        y.s().a(null, new com.ss.android.socialbase.downloader.e.a(1, stringWriter), 1);
    }

    public static boolean k() {
        return Looper.myLooper() == Looper.getMainLooper();
    }

    public static boolean l(c.j.a.a.a.c.d dVar) {
        return dVar == null ? false : d(dVar.v(), dVar.r(), dVar.s()).a();
    }

    public static boolean m(String str) {
        return !TextUtils.isEmpty(str) ? new File(str).exists() : false;
    }

    public static void n() {
        j(new Throwable());
    }

    public static boolean o(c.j.a.b.a.c.a aVar) {
        if (aVar == null) {
            return false;
        }
        return d(aVar.e, aVar.k, aVar.l).a();
    }

    public static boolean p(Context context, String str) {
        if (context == null) {
            context = y.a();
        }
        if (context == null || TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            if (context.getPackageManager().getPackageInfo(str, 0) != null) {
                return true;
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }
}
